// 引入二次封装的axios
import request from "@/utils/request";
import type { AddOrUpdateUser, AllOrderStateResponseData, AllUserResponseData, UserOrderInfoResponseData, UserParams, CertationTypeResponseData, UserInfoResponseData, PayReslt, QrCode, SubmitOrder, OrderResponseData } from './type';
// 枚举地址
enum API {
    // 提交订单,获取订单号码
    SUBMITORDER_URL = '/order/orderInfo/auth/submitOrder/',
    // 获取订单详情的数据
    GETORDERINFO_URL = '/order/orderInfo/auth/getOrderInfo/',
    // 取消订单
    ORDERCANCEL_URL = '/order/orderInfo/auth/cancelOrder/',
    // 获取支付订单二维码
    QRCODE_URL = '/order/weixin/createNative/',
    // 查询订单支付的结果
    PAYRESULT_URL = '/order/weixin/queryPayStatus/',
    // 获取当前账号用户信息
    USERINFO_URL = '/user/auth/getUserInfo',
    // 获取证件的类型的接口地址
    CERTIFICATIONTYPE_URL = '/cmn/dict/findByDictCode/',
    // 用户认证的结构
    USERCERTATION_URL = '/user/auth/userAuah',
    // 获取用户订单号的数据
    USERORDERINFO_URL = '/order/orderInfo/auth/',
    // 获取全部就诊人的信息
    ALLUSER_URL = '/user/patient/auth/findAll',
    // 获取全部订单的状态
    ORDERSTATE_URL = '/order/orderInfo/auth/getStatusList',
    // 获取城市的数据
    CITY_URL = '/cmn/dict/findByParentId/',
    // 新增就诊人
    ADDUSER_URL = '/user/patient/auth/save',
    // 更新已有的就诊人
    UPDATEUSER_URL = '/user/patient/auth/update',
    // 删除已有的就诊人
    DELETEUSER_URL = '/user/patient/auth/remove/'
};

// 提交订单,获取订单号码接口
export const reqSubmitOrder = (hoscode: string, scheduleId: string, patientId: number) => {
    return request<any, SubmitOrder>({
        url: API.SUBMITORDER_URL + `${hoscode}/${scheduleId}/${patientId}`,
        method: 'post'
    });
};

// 获取订单详情的接口
export const reqOrderInfo = (id: string) => {
    return request<any, OrderResponseData>({
        url: API.GETORDERINFO_URL + id,
        method: 'get'
    });
}

// 取消订单的接口
export const reqCancelOrder = (id: string) => {
    return request<any, any>({
        url: API.ORDERCANCEL_URL + id,
        method: 'get'
    });
}

// 获取支付二维码接口
export const reqQrcode = (orderId: string) => {
    return request<any, QrCode>({
        url: API.QRCODE_URL + orderId,
        method: 'get'
    });
}

// 查询订单支付的结果接口
export const reqQueryPayState = (orderId: string) => {
    return request<any, PayReslt>({
        url: API.PAYRESULT_URL + orderId,
        method: 'get'
    });
}

//获取当前用户信息的接口
export const reqUserInfo = () => {
    return request<any, UserInfoResponseData>({
        url: API.USERINFO_URL,
        method: 'get'
    });
}

// 获取证件类型的接口
export const reqCertationType = (CertificatesType = 'CertificatesType') => {
    return request<any, CertationTypeResponseData>({
        url: API.CERTIFICATIONTYPE_URL + CertificatesType,
        method: 'get'
    });
}
// 用户认证接口
export const reqUserCertation = (data: UserParams) => {
    return request<any, any>({
        url: API.USERCERTATION_URL,
        method: 'post',
        data
    });
}

// 获取订单数据接口
export const reqUserOrderInfo = (page: number, limit: number, patientId: string, orderStatus: string) => {
    return request<any, UserOrderInfoResponseData>({
        url: API.USERORDERINFO_URL + `${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`,
        method: 'get'
    })
}

// 获取全部就诊人信息的接口
export const reqAllUser = () => {
    return request<any, AllUserResponseData>({
        url: API.ALLUSER_URL,
        method: 'get'
    })
}

// 获取全部订单的接口
export const reqOrderState = () => {
    return request<any, AllOrderStateResponseData>({
        url: API.ORDERSTATE_URL,
        method: 'get'
    })
}

// 获取城市数据的接口
export const reqCity = (parentId: string) => {
    return request<any, any>({
        url: API.CITY_URL + parentId,
        method: 'get'
    })
}

// 新增与修改已有的就诊人接口
export const reqAddOrUpdateUser = (data: AddOrUpdateUser) => {
    if (data.id) {
        return request<any, any>({
            url: API.UPDATEUSER_URL,
            method: 'put',
            data
        })
    } else {
        return request<any, any>({
            url: API.ADDUSER_URL,
            method: 'post',
            data
        })
    }
}

// 删除某一个就诊人的接口
export const reqRemoveUser = (id: number) => {
    return request<any, any>({
        url: API.DELETEUSER_URL + id,
        method: 'delete',
    })
}